#include("../../comm/ListHead.html")
<div class="layui-fluid layui-anim layui-anim-scale">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header SearchTable">
                    <p style="float:right"></p>
                    <label class="table-search-title-first">条件:</label>
                    <input type="text" id="s_keyid" lay-verify="required" placeholder="主键ID" autocomplete="off"
                           class="table-search-text width80">
                    <input type="text" id="s_title" lay-verify="required" placeholder="标题" autocomplete="off"
                           class="table-search-text width120">
                    <button class="layui-btn layui-btn-warm layui-btn-sm" data-type="DoSearch">
                        搜索
                    </button>
                </div>
                <div class="layui-card-body">
                    <table class="layui-hide" id="table_1" lay-filter="table_1"></table>

                    <script type="text/html" id="table_1_bar_title">
                        <div class="layui-btn-container">
                            <button class="layui-btn layui-btn-sm" lay-event="AddNotice">添加通知</button>
                            <button class="layui-btn layui-btn-sm" lay-event="EditNotice">修改通知</button>
                        </div>
                    </script>

                    <script type="text/html" id="TplPub">
                        <input type="checkbox" name="pub_tag" value="{{d.not_id}}" title="发布" lay-filter="PubNotice" {{ d.pub_tag ? 'checked' : '' }}>
                    </script>
                    <script type="text/html" id="TplTest">
                        <input type="checkbox" name="test_tag" value="{{d.not_id}}" title="发布" lay-filter="TestNotice" {{ d.test_tag ? 'checked' : '' }}>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="../../static/plugins/layui/layui.js"></script>
<script language="JavaScript">
    var USER_JWT = "";
    var index = 0;
    var admin;
    var table, tableindex;

    layui.config({
        base: '../../static/plugins/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'form'], function () {
        admin = layui.admin, table = layui.table, form = layui.form;
        tableindex = table.render({
            elem: '#table_1'
            , url: 'SysNoticeListDataApi'
            , toolbar: '#table_1_bar_title'
            , title: '通知列表'
            , cols: [[
                         {type: 'radio', fixed: 'left'}
                         , {field: 'not_id', title: 'ID', width: 60, fixed: 'left', align: 'center', unresize: true}
                         , {field: 'sindex', title: '顺序', align: 'center', width: 70, edit: 'text'}
                         , {field: 'not_title', title: '标题', align: 'left', width: 400}
                         , {field: 'not_times', title: '发布时间', align: 'center', width: 150}
                         , {title: '备注', hide: false}
                         , {title: '发布', templet: '#TplPub', width: 120, align: 'center'}
                         , {title: '测试', templet: '#TplTest', width: 120, align: 'center'}
                     ]]
            , page: true
            , limit: 10
        });

        //搜索 和重载
        var $ = layui.$, active = {
            SearchReload: function () {
                tableindex.reload({});
            },
            DoSearch: function () {
                tableindex.reload({
                    where: {
                        s: {
                            keyid: $("#s_keyid").val(),
                            title: $("#s_title").val()
                        }
                    }
                    , page: {curr: 1}
                });
            }
        };

        //头工具栏事件
        table.on('toolbar(table_1)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'AddNotice'://添加通知
                    index = layer.open({
                        type: 2, offset: '10px', area: ['800px', '550px'], title: ['添加通知', 'font-size:15px;'], content: ["AddSysNotice", 'no'],
                        end: function () {
                            tableindex.reload();
                        }
                    });
                    break;
                case 'EditNotice'://修改通知
                    var checkStatus = table.checkStatus('table_1'), data = checkStatus.data;
                    if (data.length != 1) {
                        layer.msg('请选择您要修改的通知');
                    } else {
                        index = layer.open({
                            type: 2, offset: '10px', area: ['800px', '550px'],
                            title: ['修改通知[' + data[0].not_title + ']', 'font-size:15px;'],
                            content: ["EditSysNotice?not_id=" + data[0].not_id, 'no'],
                            end: function () {
                                tableindex.reload();
                            }
                        });
                    }
                    break;
            }
        });

        //监听单元格编辑
        table.on('edit(table_1)', function (obj) {
            var value = obj.value, data = obj.data, field = obj.field; //得到字段
            layui_ext.AjaxPostJson($, layer, "ModifySysNoticeFieldApi",
                    {not_id: data.not_id, field: field, values: value});
        });

        //监听锁定操作
        form.on('checkbox(PubNotice)', function (obj) {
            $.get("PubSysNoticeApi", {not_id: this.value}, function (result) {
                layer.tips(result.msg, obj.othis);
            });
        });

        //监听锁定操作
        form.on('checkbox(TestNotice)', function (obj) {
            $.get("TestSysNoticeApi", {not_id: this.value}, function (result) {
                layer.tips(result.msg, obj.othis);
            });
        });

        //搜索按钮事件监控
        $('.SearchTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>
</body>
</html>